import { JsonController, Authorized, Body, HeaderParam, Get, Post, UseBefore, QueryParam} from 'routing-controllers';
import { RequestLog } from '@/middleware/requestLog'
import { Inject, Service } from 'typedi';
import { MenuServiceImpl } from '@/impl/MenuServiceImpl';
import { JsonResult, msgList, res } from '@/utils/jsonResult';
import config from '@/config'
import { addMenuParams } from '@/model/request/Menu';
import { Token } from '@/m_req/Token'

@Service()
@JsonController(config.setPrefix("admin/menu"))
export class MenuController {

  @Inject()
  menuServiceImpl!: MenuServiceImpl;

  @Inject()
  json!: JsonResult<any>;


  @Get('/list')
  @UseBefore(RequestLog)
  async MenuList() {
    return this.menuServiceImpl.GetAllMenu();
  }

  @Post('/add')
  @UseBefore(RequestLog)
  @Authorized()
  async MenuAdd(@Body() params: addMenuParams) {
    return this.menuServiceImpl.addMenu(params);
  }

  @Post('/delete')
  @UseBefore(RequestLog)
  async Menudelete(@Body() params:{id:number}) {
    return this.menuServiceImpl.deleteMenu(params);
  }

  @Post('/updata')
  @UseBefore(RequestLog)
  @Authorized()
  async Menuupdata(@Body() params: addMenuParams) {
    return this.menuServiceImpl.Menuupdata(params);
  }

  
  @Post('/sions')
  @UseBefore(RequestLog)
  @Authorized()
  async Menusions(@HeaderParam("token") token: Token) {
    return this.menuServiceImpl.Menusions(token);
  }
}